package ystp.service;

import org.springframework.stereotype.Service;
import ystp.dao.YsxiangmuMapper;
import ystp.model.Ysxiangmu;
import ystp.model.YsxiangmuExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class YsxiangmuService {

    @Resource
    YsxiangmuMapper ddMapper;

    public List<Map<String, Object>> findAllBypage(String ppxiangmuName, int ppPageIndex, int ppPageSize) {
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findAllBypage(ppxiangmuName, mmStartIndex, ppPageSize);
    }

    public Integer getCount(String ppxiangmuName) {
        Object mmCount = ddMapper.getCount(ppxiangmuName);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public Ysxiangmu findOne(String ppxiangmuId) {
        return ddMapper.selectByPrimaryKey(ppxiangmuId);
    }

    public boolean add(Ysxiangmu ppYsxiangmu) {
        return ddMapper.insert(ppYsxiangmu) == 1;
    }

    public boolean modify(Ysxiangmu ppYsxiangmu) {
        return ddMapper.updateByPrimaryKeySelective(ppYsxiangmu) == 1;
    }

    public Ysxiangmu getIsactivedxiangmu() {
        YsxiangmuExample mmexample = new YsxiangmuExample();
        YsxiangmuExample.Criteria criteria = mmexample.createCriteria();
        criteria.andIsactivedEqualTo(1);
        return ddMapper.selectByExample(mmexample).size() > 0 ? ddMapper.selectByExample(mmexample).get(0) : null;

    }

    /**
     * 查询所有有效项目
     * 
     * @return 项目列表
     */
    public List<Ysxiangmu> findAll() {
        YsxiangmuExample mmexample = new YsxiangmuExample();
        YsxiangmuExample.Criteria criteria = mmexample.createCriteria();
        criteria.andStatusEqualTo(100);
        return ddMapper.selectByExample(mmexample);
    }

    public boolean modifyisactived(String ppXiangmuId, int ppIsactive) {
        // Ysxiangmu mmYsxiangmu = new Ysxiangmu();
        // mmYsxiangmu.setIsactived(0);
        // YsxiangmuExample mmexample = new YsxiangmuExample();
        // YsxiangmuExample.Criteria criteria = mmexample.createCriteria();
        // ddMapper.updateByExampleSelective(mmYsxiangmu,mmexample);

        Ysxiangmu mmYsxiangmu = new Ysxiangmu();
        mmYsxiangmu.setXiangmuid(ppXiangmuId);// 设置目标项目为活动状态
        mmYsxiangmu.setIsactived(ppIsactive);
        return modify(mmYsxiangmu);
    }

    public boolean modifynoactived() {
        return ddMapper.updateBynoactived() == 1;
    }
}
